import Vue from 'vue'
import Vuex from 'vuex'
import vuexPersist from "vuex-persist"

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    toDoList:[],
    selList:[]
  },
  mutations: {
    ADDTODO(state,obj){
      state.toDoList.push(obj)
    },
    CHANGESYA(state,f){
      state.toDoList.forEach((el,index)=>{
        if(index == f){
          if(el.status == 0){
            el.status =1
          }else{
            el.status = 0;
          }
        }
      })
    },
    CANCEL(state,s){
      state.toDoList.forEach((el,index)=>{
        if(index == s){
          if(el.status == 0){
            el.status =2
          }else{
            el.status = 0;
          }
        }
      })
    },
    CLOSECANCLE(state,s){
      state.toDoList.forEach((el,index)=>{
        if(index == s){
          if(el.status == 2){
            el.status =0
          }else{
            el.status = 2;
          }
        }
      })
    },
    SEARVH(state,f){
      if(f == -1){
        state.selList = state.toDoList
      }
      console.log(state.selList)
    }
  },
  actions: {
  },
  modules: {
  },
  plugins: [
    new vuexPersist({
      storage: window.localStorage,
    }).plugin,
  ],
})
